package com.kamistoat.meimeimall.common.sharding.properties;

import lombok.Data;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

import java.util.Map;

/**
 * 数据源配置解析Bean，从属于 ShardingProperties
 * 自定义配置需要按照下述格式:
 * sharding:
 *   databases:
 *     base1:
 *       shardingDatabaseCount:
 *       shardingDataTableCount:
 *       dataSource:
 *         master:
 *           1:
 *             driverClassName=com.mysql.jdbc.Driver
 *             url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8
 *             username=root
 *             password=root
 *           2:
 *             driverClassName=com.mysql.jdbc.Driver
 *             url=jdbc:mysql://127.0.0.2:3306/test?useUnicode=true&characterEncoding=utf-8
 *             username=root
 *             password=root
 *         slave:
 *
 *     base2:
 */
@Data
public class DatabaseProperties {
    /**
     * 分库数量
     */
    private Integer shardingDatabaseCount;
    /**
     * 每个库的分表数量
     */
    private Integer shardingPreTableCount;
    /**
     * 解析Spring原生数据源链接配置。
     * String: 主从标识，master/slave
     * Integer: 第几个分库。
     * DataSourceProperties: Spring原生数据源链接配置
     */
    private Map<String, Map<Integer, DataSourceProperties>> dataSource;

}
